package com.chiv.hystrix.service.impl;

import com.chiv.hystrix.service.PersonService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;

@Service
public class PersonServiceImpl implements PersonService {
    @Autowired
    RestTemplate restTemplate;
    @Value("${service-url}")
    String url;

    //fallbackMethod 当调起服务失败时【user-service】，服务降级执行的方法
    @HystrixCommand(fallbackMethod = "getDefaultList")
    @Override
    public Object getList() {
        return restTemplate.getForEntity(url+"/good/list",Object.class);
    }

    public  Object getDefaultList(){
        return new ArrayList<>();
    }
}
